package com.vue.power.backend.sys.controller;

import com.vue.power.backend.common.base.constant.SystemStaticConst;
import com.vue.power.backend.common.base.controller.BaseController;
import com.vue.power.backend.common.base.entity.Page;
import com.vue.power.backend.common.base.service.BaseService;
import com.vue.power.backend.sys.entity.RoleTree;
import com.vue.power.backend.sys.service.RoleTreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 类描述：实现菜单模块的controller
 */
@RestController
@RequestMapping(value = "/tree")
public class TreeController extends BaseController<RoleTree> {

    @Autowired
    private RoleTreeService roleTreeService;

    @Override
    protected BaseService<RoleTree> getService() {
        return this.roleTreeService;
    }

    /**
     * 功能描述：更新按钮节点状态
     * @param entity
     * @return
     */
    @PostMapping("operateTreeButton")
    public Map<String,Object> operateTreeButton(@RequestBody RoleTree entity){
        Map<String,Object> result = new HashMap<String, Object>();
        if(roleTreeService.operateTreeButton(entity)){
            result.put(SystemStaticConst.RESULT, SystemStaticConst.SUCCESS);
            result.put(SystemStaticConst.MSG,"更新按钮节点状态成功！");
        }else{
            result.put(SystemStaticConst.RESULT, SystemStaticConst.FAIL);
            result.put(SystemStaticConst.MSG,"更新按钮节点状态失败！");
        }
        return result;
    }

    /**
     * 功能描述：获取数据字典的分页的数据
     * @param query
     * @return
     */
    @PostMapping("queryTreeButtonList")
    public Map<String,Object> queryTreeButtonList(@RequestBody Map<String,Object> query){
        Map<String,Object> result = new HashMap<>();
        Page page = roleTreeService.commonQueryList(query);
        result.put("totalCount",page.getTotal());
        result.put("result",page.getRows());
        return result;
    }

    /**
     * 功能描述：获取所有的树形菜单的数据
     * @return
     */
    @PostMapping("getAllTreeList")
    public Map<String,Object> getAllTreeList(){
        return roleTreeService.getAllTreeList(true);
    }

    @Override
    public Map<String, Object> save(@RequestBody RoleTree entity) throws Exception {
        return super.save(entity);
    }

    @Override
    public Map<String, Object> update(@RequestBody RoleTree entity) throws Exception {
        return super.update(entity);
    }

    @Override
    public Map<String, Object> remove(@RequestBody RoleTree entity) throws Exception {
        return super.remove(entity);
    }

    @Override
    public Map<String, Object> removeBath(@RequestBody String json) throws Exception {
        return super.removeBath(json);
    }

    @Override
    public Map<String, Object> list(@RequestBody RoleTree entity) {
        return super.list(entity);
    }
}
